package cn.liyicun.cp.cpweb.controller.admin;

import cn.liyicun.cp.cpweb.base.Result;
import cn.liyicun.cp.cpweb.entity.UserInfo;
import cn.liyicun.cp.cpweb.service.UserInfoService;
import cn.liyicun.cp.cpweb.util.CPConstant;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping(value = {CPConstant.ROOT_PHONE_ADMIN + "/user"})
public class UserInfoAdminController extends BaseAdminController {

    @Autowired
    UserInfoService userInfoService;

    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    @ResponseBody
    public Result<?> updateStatus(@RequestParam(value = "id", required = true) Long id,
                                  @RequestParam(value = "status", required = true) int status) {


        userInfoService.updateStatus(id, status);

        return Result.success("成功!");
    }


    @RequestMapping(value = "/searchUserInfo")
    public String searchUserInfo(HttpServletRequest request, Map<String, Object> map,
                                 @RequestParam(value = "uid", required = false, defaultValue = "0") Long uid,
                                 @RequestParam(value = "userName", required = false) String userName,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                 @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        getLoginByIdError(request);
        PageInfo<UserInfo> pages = userInfoService.search(uid, userName, page, size);
        map.put("pages", pages);
        map.put("uid", uid);
        map.put("userName", userName);
        return "admin/searchUserInfo";
    }
}
